﻿using System;

namespace Common
{
    public class NumberHelper
    {
        public static string GetRatio(int? a, int? b)
        {
            if (!a.HasValue || a == 0 || !b.HasValue || b == 0)
            {
                return "--";
            }

            return (((double)a.Value / b.Value)).ToString("0%");
        }

        public static string GetRatio(int a, int b)
        {
            if (b == 0)
            {
                return "--";
            }

            if (a == 0)
            {
                return "0%";
            }

            return (((double)a / b)).ToString("0%");
        }

        public static decimal GetDecimalRatio(int a, int b)
        {
            if (a == 0 || b == 0)
            {
                return 0;
            }

            return Math.Round(((decimal)a / b) * 100, 2, MidpointRounding.AwayFromZero);
        }

        public static int GetIntRatio(int a, int b)
        {
            if (a == 0 || b == 0)
            {
                return 0;
            }

            return (int)Math.Round(((decimal)a / b) * 100, 0, MidpointRounding.AwayFromZero);
        }


        public static int GetDivideValue(int a, int b)
        {
            if (a == 0 || b == 0)
            {
                return 0;
            }

            return (int)Math.Round(((decimal)a / b) , 0, MidpointRounding.AwayFromZero);
        }

        public static int GetIntRatio(int a, double b1)
        {
            int b = Double2Int(b1);
            if (a == 0 || b == 0)
            {
                return 0;
            }

            return (int)Math.Round(((decimal)a / b) * 100, 0, MidpointRounding.AwayFromZero);
        }

        public static int Double2Int(double d)
        {
            return (int)Math.Round(d, 0, MidpointRounding.AwayFromZero);
        }

        public static int GetTheGreater(int a, int b)
        {
            return a > b ? a : b;
        }

        public static int GetTheSmaller(int a, int b)
        {
            return a < b ? a : b;
        }

        public static int GetDValue(int a, int b)
        {
            return Math.Abs(a - b);
        }
    }
}
